home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / VideoFolder 1.0a / Source / MoreFiles 1.4.1 / FullPath.h < prev    next >
Text File  |  1995-12-21  |  7KB  |  187 lines

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Routines for dealing with full pathnames... if you really must.
  5. **
  6. **    by Jim Luther, Apple Developer Technical Support Emeritus
  7. **
  8. **    File:        FullPath.h
  9. **
  10. **    Copyright © 1995 Apple Computer, Inc.
  11. **    All rights reserved.
  12. **
  13. **    You may incorporate this sample code into your applications without
  14. **    restriction, though the sample code has been provided "AS IS" and the
  15. **    responsibility for its operation is 100% yours.  However, what you are
  16. **    not permitted to do is to redistribute the source as "DSC Sample Code"
  17. **    after having made changes. If you're going to re-distribute the source,
  18. **    we require that you make it clear in the source that the code was
  19. **    descended from Apple Sample Code, but that you've made changes.
  20. */
  21.  
  22. #ifndef __FULLPATH__
  23. #define __FULLPATH__
  24.  
  25. #include <Types.h>
  26. #include <Files.h>
  27.  
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31.  
  32. /*
  33.     IMPORTANT NOTE:
  34.     
  35.     The use of full pathnames is strongly discouraged. Full pathnames are
  36.     particularly unreliable as a means of identifying files, directories
  37.     or volumes within your application, for two primary reasons:
  38.     
  39.     •     The user can change the name of any element in the path at
  40.         virtually any time.
  41.     •    Volume names on the Macintosh are *not* unique. Multiple
  42.         mounted volumes can have the same name. For this reason, the use of
  43.         a full pathname to identify a specific volume may not produce the
  44.         results you expect. If more than one volume has the same name and
  45.         a full pathname is used, the File Manager currently uses the first
  46.         mounted volume it finds with a matching name in the volume queue.
  47.     
  48.     In general, you should use a file’s name, parent directory ID, and
  49.     volume reference number to identify a file you want to open, delete,
  50.     or otherwise manipulate.
  51.     
  52.     If you need to remember the location of a particular file across
  53.     subsequent system boots, use the Alias Manager to create an alias
  54.     record describing the file. If the Alias Manager is not available, you
  55.     can save the file’s name, its parent directory ID, and the name of the
  56.     volume on which it’s located. Although none of these methods is
  57.     foolproof, they are much more reliable than using full pathnames to
  58.     identify files.
  59.     
  60.     Nonetheless, it is sometimes useful to display a file’s full pathname
  61.     to the user. For example, a backup utility might display a list of full
  62.     pathnames of files as it copies them onto the backup medium. Or, a
  63.     utility might want to display a dialog box showing the full pathname of
  64.     a file when it needs the user’s confirmation to delete the file. No
  65.     matter how unreliable full pathnames may be from a file-specification
  66.     viewpoint, users understand them more readily than volume reference
  67.     numbers or directory IDs.
  68.     
  69.     The following technique for constructing the full pathname of a file is
  70.     intended for display purposes only. Applications that depend on any
  71.     particular structure of a full pathname are likely to fail on alternate
  72.     foreign file systems or under future system software versions.
  73. */
  74.  
  75. /*****************************************************************************/
  76.  
  77. pascal    OSErr    GetFullPath(short vRefNum,
  78.                             long dirID,
  79.                             StringPtr name,
  80.                             short *fullPathLength,
  81.                             Handle *fullPath);
  82. /*    ¶ Get a full pathname to a volume, directory or file.
  83.     The GetFullPath function builds a full pathname to the specified
  84.     object. The full pathname is returned in the newly created handle
  85.     fullPath and the length of the full pathname is returned in
  86.     fullPathLength. Your program is responsible for disposing of the
  87.     fullPath handle.
  88.     
  89.     vRefNum            input:    Volume specification.
  90.     dirID            input:    Directory ID.
  91.     name            input:    Pointer to object name, or nil when dirID
  92.                             specifies a directory that's the object.
  93.     fullPathLength    output:    The number of characters in the full pathname.
  94.                             If the function fails to create a full
  95.                             pathname, it sets fullPathLength to 0.
  96.     fullPath        output:    A handle to the newly created full pathname
  97.                             buffer. If the function fails to create a
  98.                             full pathname, it sets fullPath to NULL.
  99.  
  100.     __________
  101.     
  102.     See also:    FSpGetFullPath
  103. */
  104.  
  105. /*****************************************************************************/
  106.  
  107. pascal    OSErr    FSpGetFullPath(const FSSpec *spec,
  108.                                short *fullPathLength,
  109.                                Handle *fullPath);
  110. /*    ¶ Get a full pathname to a volume, directory or file.
  111.     The GetFullPath function builds a full pathname to the specified
  112.     object. The full pathname is returned in the newly created handle
  113.     fullPath and the length of the full pathname is returned in
  114.     fullPathLength. Your program is responsible for disposing of the
  115.     fullPath handle.
  116.     
  117.     spec            input:    An FSSpec record specifying the object.
  118.     fullPathLength    output:    The number of characters in the full pathname.
  119.                             If the function fails to create a full pathname,
  120.                             it sets fullPathLength to 0.
  121.     fullPath        output:    A handle to the newly created full pathname
  122.                             buffer. If the function fails to create a
  123.                             full pathname, it sets fullPath to NULL.
  124.  
  125.     __________
  126.     
  127.     See also:    GetFullPath
  128. */
  129.  
  130. /*****************************************************************************/
  131.  
  132. pascal OSErr FSpLocationFromFullPath(short fullPathLength,
  133.                                      const void *fullPath,
  134.                                      FSSpec *spec);
  135. /*    ¶ Get a FSSpec from a full pathname.
  136.     The FSpLocationFromFullPath function returns a FSSpec to the object
  137.     specified by full pathname. This function requires the Alias Manager.
  138.     
  139.     fullPathLength    input:    The number of characters in the full pathname
  140.                             of the target.
  141.     fullPath        input:    A pointer to a buffer that contains the full
  142.                             pathname of the target. The full pathname
  143.                             starts ith the name of the volume, includes
  144.                             all of the directory names in the path to the
  145.                             target, and ends with the target name.
  146.     spec            output:    An FSSpec record specifying the object.
  147.  
  148.     __________
  149.     
  150.     See also:    LocationFromFullPath
  151. */
  152.  
  153. /*****************************************************************************/
  154.  
  155. pascal OSErr LocationFromFullPath(short fullPathLength,
  156.                                   const void *fullPath,
  157.                                   short *vRefNum,
  158.                                   long *parID,
  159.                                   Str31 name);
  160. /*    ¶ Get an object's location from a full pathname.
  161.     The LocationFromFullPath function returns the volume reference number,
  162.     parent directory ID and name of the object specified by full pathname.
  163.     This function requires the Alias Manager.
  164.     
  165.     fullPathLength    input:    The number of characters in the full pathname
  166.                             of the target.
  167.     fullPath        input:    A pointer to a buffer that contains the full
  168.                             pathname of the target. The full pathname starts
  169.                             with the name of the volume, includes all of
  170.                             the directory names in the path to the target,
  171.                             and ends with the target name.
  172.     vRefNum            output:    The volume reference number.
  173.     parID            output:    The parent directory ID of the specified object.
  174.     name            output:    The name of the specified object.
  175.  
  176.     __________
  177.     
  178.     See also:    FSpLocationFromFullPath
  179. */
  180.  
  181. /*****************************************************************************/
  182.  
  183. #ifdef __cplusplus
  184. }
  185. #endif
  186.  
  187. #endif    /* __FULLPATH__ */